home *** CD-ROM | disk | FTP | other *** search
/ Aminet 12 / Aminet 12 (1996)(GTI - Schatztruhe)[!][Jun 1996].iso / Aminet / util / boot / CyberMap.lha / CyberMap.asm
Encoding:
Assembly Source File  |  1996-04-15  |  11.9 KB  |  462 lines

  1.  
  2. ****************************************************************************
  3. **  /\  |\     Silicon Department      Telefax     06404-64760
  4. **  \_ o| \_ _  Software Entwicklung    Telefon        06404-7996
  5. **    \|| |_)|)   Carsten Schlote         Egelseeweg 52     35423 Lich
  6. ** \__/||_/\_|     Branko Mikiç            Limmerstrasse 10   30451 Hannover
  7. ****************************************************************************
  8. *
  9. * $Id: CyberMap.asm 1.5 1996/03/29 11:10:28 schlote Exp schlote $
  10. *
  11. *    29/11/95      39.2    ExtraTexts added
  12. *    28/12/95    39.3    Small Bug Fix with SysCall
  13. *       06/01/95      39.4    Changed RESET Code
  14. *    23/03/96    39.5ß    Added B2060 support
  15. *    27/03/96        39.5ß    Changed CLR.W (4).W -> MOVE.L    #-1,(4).w;  Hint by Don & Gerald :-)
  16. *                Debugged B2060 Routine.
  17. *    28/03/96    39.5ß    Added release note and send mail
  18. *    29/03/96    39.5    Fixed A2000 Reset Code, First release, fixed version id
  19.  
  20.         incdir         include:
  21.         include     "dos/dos.i"
  22.         include        "exec/funcdef.i"
  23.         include        "exec/exec_lib.i"
  24.         include        "exec/exec.i"
  25.         include        "exec/lists.i"
  26.         include        "exec/execbase.i"
  27.         include        "exec/memory.i"
  28.         include        "dos/dos_lib.i"
  29.         include        "hardware/intbits.i"
  30.         include        "hardware/custom.i"
  31.  
  32. _LVOFreeArgs    EQU        -$35A                * Stehen noch nicht in dos_lib.i
  33. _LVOPutStr    EQU        -$3B4
  34. _LVOPrintFault    EQU        -$1DA
  35. _LVOReadArgs    EQU        -$31E
  36.  
  37. _custom        EQU        $DFF000
  38.  
  39.         MACHINE        68030
  40.         opt !
  41.  
  42. ****************************************************************************************************************
  43.  
  44. KickMem        EQUR        a3
  45. SysBase        EQUR        a4
  46. DOSBase        EQUR        a5
  47.  
  48.         SECTION        CyberMap_Main,CODE
  49. ProgStart
  50.         MOVEQ        #20,D7                      ; RC=20
  51.         MOVE.L        (4).w,SysBase            ; A4=SysBase
  52.  
  53.         LEA        (doslibrary.MSG,PC),A1        ; A5=DOSBase
  54.         MOVEQ        #37,D0
  55.         MOVE.L        SysBase,A6
  56.         JSR        (_LVOOpenLibrary,A6)
  57.         MOVE.L        d0,DOSBase
  58.         BEQ.W        .nodoslib
  59.  
  60.         LEA        (Template,PC),A1        ; Argumente parsen
  61.         MOVE.L        A1,D1
  62.         LEA        (ArgsEntry0,PC),A1
  63.         MOVE.L        A1,D2
  64.         MOVEQ        #0,D3
  65.         move.L        DOSBase,A6
  66.         JSR        (_LVOReadArgs,A6)
  67.         LEA        (ArgsHandle,PC),a0
  68.         MOVE.L        D0,(a0)
  69.         BNE.B        .argsoks
  70.  
  71.         JSR        (_LVOIoErr,A6)            ; ReadArgs failed
  72.         MOVE.L        D0,D1                          ; print reason
  73.         MOVEQ        #0,D2
  74.         JSR        (_LVOPrintFault,A6)
  75.         BRA.B        .quit
  76.  
  77. .argsoks    MOVEQ        #0,D0    ; Check Signals
  78.         MOVE.L        D0,D1
  79.         move.L        SysBase,A6
  80.         JSR        (_LVOSetSignal,A6)
  81.  
  82.         BTST        #SIGBREAKB_CTRL_C,D0
  83.         BEQ.B        .noctrlC
  84.  
  85.         MOVE.L        #304,D1
  86.         MOVEQ        #0,D2
  87.         move.L        DOSBase,A6
  88.         JSR        (_LVOPrintFault,A6)
  89.         BRA.B        .quit
  90.  
  91. .noctrlC    MOVEQ        #0,D7                          ; RC=0
  92.  
  93.         MOVEQ        #8,D0                ; $80000 Bytes alloc
  94.         SWAP        D0
  95.         MOVEQ        #(MEMF_PUBLIC|MEMF_CHIP),D1
  96.         move.L        SysBase,A6
  97.         JSR        (_LVOAllocMem,A6)
  98.         move.L        D0,KickMem
  99.         TST.L        d0                ; A3=KickMem
  100.         BEQ.W        .quit
  101.  
  102.         move.L        (ArgsEntry0,PC),d1        ; File öffnen
  103.         MOVE.L        #MODE_OLDFILE,D2
  104.         move.L        DOSBase,A6
  105.         JSR        (_LVOOpen,A6)
  106.         MOVE.L        D0,D6    ; D6=FileHandle
  107.         BEQ.W        .freeMem
  108.  
  109.         MOVE.L        D6,D1                ; 16 Bytes einlesen
  110.         MOVE.L        KickMem,D2
  111.         MOVEQ        #16,D3
  112.         JSR        (_LVORead,A6)
  113.         CMP.L        D3,D0
  114.         BNE.W        .closefile
  115.  
  116.         move.L        #$F80000,A2            ; Kickfile Hdr == "ROM" Hdr
  117.         MOVE.L        (A2),D0
  118.         CMP.L        (KickMem),D0
  119.         BNE.W        .wrongKick
  120.  
  121.         MOVE.L        (4,A2),D0
  122.         CMP.L        (4,KickMem),D0
  123.         BNE.B        .wrongKick
  124.  
  125.         MOVE.L        (8,A2),D0
  126.         CMP.L        (8,KickMem),D0
  127.         BNE.B        .wrongKick
  128.  
  129.         MOVE.L        (12,A2),D0            ; ROM Ver != File Ver
  130.         CMP.L        (12,KickMem),D0
  131.         BNE.B        .seekBegin
  132.  
  133.                 MOVE.L        (ArgsEntry1,PC),d0        ; Force mapping
  134.         BEQ.B        .closefile                  ; for same version
  135.  
  136. .seekBegin    MOVE.L        D6,D1    ; Seek to File Start
  137.         MOVEQ        #0,D2
  138.         MOVEQ        #OFFSET_BEGINING,D3
  139.         move.L        DOSBase,A6
  140.         JSR        (_LVOSeek,A6)
  141.  
  142.         MOVE.L        D6,D1                ; Read Kick to buffer
  143.         MOVE.L        KickMem,D2
  144.         MOVEQ        #8,D3
  145.         SWAP        D3
  146.         JSR        (_LVORead,A6)
  147.         CMP.L        d3,D0
  148.         BNE.B        .closefile
  149.  
  150.         move.l        KickMem,a0
  151.         jsr        (_CheckKickSum,pc)
  152.         beq        .crcok
  153.  
  154.                 MOVE.L        (ArgsEntry1,PC),d0        ; Force mapping
  155.         BNE.B        .crcok                         ; for same version
  156.  
  157.         LEA        (BadKickCRC,PC),A0
  158.         MOVE.L        A0,D1
  159.                    move.L        DOSBase,A6
  160.         JSR        (_LVOPutStr,A6)
  161.         MOVEQ        #20,D7                ; RC=20
  162.         bra        .closefile
  163.  
  164. .crcok        move.L        SysBase,A6            ; Forbid MultiTasking
  165.         JSR        (_LVOForbid,A6)
  166.  
  167.         MOVEQ        #75,D1                ; Warten
  168.         ADD.L        D1,D1
  169.         move.L        DOSBase,A6
  170.         JSR        (_LVODelay,A6)
  171.  
  172.         MOVEQ        #(CACRF_EnableI|CACRF_IBE),D0
  173.         MOVEQ        #-1,D1
  174.         move.L        SysBase,A6
  175.         JSR        (_LVOCacheControl,A6)
  176.         MOVE.L        D0,d5                ; alte CACR Bits merken
  177.  
  178.         MOVE.L        KickMem,A0            ; KickBuff -> a0
  179.                 tst.l           ArgsEntry2
  180.                 beq.s        .maprom
  181.              JSR        _Kick2060
  182.              BRA.s        .fail
  183. .maprom
  184.         JSR        _KickIt                ; Will not return if works !!!!!
  185.  
  186. .fail
  187.         LEA        (NoMapROM,PC),A0
  188.         MOVE.L        A0,D1
  189.                    move.L        DOSBase,A6
  190.         JSR        (_LVOPutStr,A6)
  191.         MOVEQ        #20,D7                ; RC=20
  192.  
  193.         MOVE.L        d5,D0                ; alte Bits wiederholen
  194.         MOVEQ        #-1,D1
  195.         move.l        SysBase,A6
  196.         JSR        (_LVOCacheControl,A6)
  197.         JSR        (_LVOPermit,A6)
  198.         BRA.B        .closefile
  199.  
  200. .wrongKick    LEA        (InvalidKick,PC),A0
  201.         MOVE.L        A0,D1
  202.                    move.L        DOSBase,A6
  203.         JSR        (_LVOPutStr,A6)
  204.         MOVEQ        #20,D7    ; RC=20
  205.  
  206. .closefile    MOVE.L        D6,D1
  207.                    move.L        DOSBase,A6
  208.         JSR        (_LVOClose,A6)
  209.  
  210. .freeMem    move.L        KickMem,A1
  211.         MOVEQ        #8,D0
  212.         SWAP        D0
  213.         move.L        SysBase,A6
  214.         JSR        (_LVOFreeMem,A6)
  215.  
  216. .quit        MOVE.L        (ArgsHandle,PC),D1
  217.         BEQ.B        .noArgs
  218.         move.L        DOSBase,A6
  219.         JSR        (_LVOFreeArgs,A6)
  220.  
  221. .noArgs        move.L        a6,A1
  222.         move.L        SysBase,A6
  223.         JSR        (_LVOCloseLibrary,A6)
  224.  
  225. .nodoslib    MOVE.L        D7,D0
  226.         RTS
  227.  
  228. ****************************************************************************************************************
  229. **    a0 = KickMem
  230. **    d0 == 0 -> OK
  231. ****************************************************************************************************************
  232.  
  233. _CheckKickSum:    movem.l        d2,-(sp)
  234.  
  235.         MOVEQ        #0,D1            * Laufvaraiblen
  236.         MOVEQ        #0,D0
  237.  
  238.         MOVE.L        #($80000/16)-1,D2
  239.  
  240. .loop        ADD.L        (A0)+,D0
  241.         ADDX.L        D1,D0
  242.         ADD.L        (A0)+,D0
  243.         ADDX.L        D1,D0
  244.         ADD.L        (A0)+,D0
  245.         ADDX.L        D1,D0
  246.         ADD.L        (A0)+,D0
  247.         ADDX.L        D1,D0
  248.         DBRA        D2,.loop
  249.  
  250.         ADDQ.L        #1,D0
  251.         movem.l        (sp)+,d2
  252.                 TST.L       d0
  253.                 RTS
  254.  
  255. ****************************************************************************************************************
  256.  
  257. ArgsHandle    dc.l        0            ; ReadArgs Stuff
  258. ArgsEntry0    dc.l        0
  259. ArgsEntry1      dc.l        0
  260. ArgsEntry2      dc.l        0
  261.  
  262. doslibrary.MSG    dc.b    'dos.library',0
  263. Template    dc.b    'FILE/A,F=FORCE/S,B2=B2060/S',0
  264.         dc.b    '$VER: CyberMap 39.5 (29.03.96)\n'
  265.         dc.b    '©1995,1996 by Carsten Schlote. Written for phase5 digital products.\r\n',0,0
  266. InvalidKick    dc.b    'Invalid Kickstart file.',$A,0
  267. BadKickCRC    dc.b    'Checksum failure on Kickimage.',$A,0
  268. NoMapROM    dc.b    'No mapping hardware detected or hardware malfunction.',10,0
  269.  
  270.  
  271. ****************************************************************************************************************
  272.  
  273. INTFLAGS    equ    (INTF_TBE|INTF_DSKBLK|INTF_SOFTINT|INTF_PORTS|INTF_COPER|INTF_VERTB|INTF_BLIT|INTF_AUD0|INTF_AUD1|INTF_AUD2|INTF_AUD3|INTF_RBF|INTF_DSKSYNC|INTF_EXTER)
  274.  
  275.         SECTION        CyberMap_CyberStorm,CODE_C
  276.  
  277. _KickIt        MOVEM.L        A5/A6,-(SP)
  278.         move.L        (4).W,A6
  279.         LEA        (_KickSuperCode,PC),A5
  280.         JSR        (_LVOSupervisor,A6)
  281.         MOVEM.L        (SP)+,A5/A6
  282.         RTS
  283.  
  284.  
  285. _KickSuperCode
  286.         ORI.W        #$700,SR        ; Lock all IRQs !
  287.  
  288.         MOVE.B        #0,($DE0000).L        ; Gary BootFlags = ColdStart
  289.         MOVE.B        #0,($DE0001).L
  290.  
  291.         NOP
  292.         MOVE.L        #1,($80F80000).L    ; Trigger MapROM
  293.  
  294.         NOP                                 ; Sync Pipelines
  295.         MOVE.L        ($7F80000).L,D0         ; Hat es funktioniert ?
  296.         CMP.L        ($F80000).L,D0
  297.         BNE.B        .MapROMfail
  298.  
  299.         MOVE.L        D0,D1            ; Zweiter Test...
  300.         NOT.L        D1
  301.         MOVE.L        D1,($7F80000).L
  302.         CMP.L        ($F80000).L,D1
  303.         BEQ.B        .MapROMok
  304.  
  305.         MOVE.L        D0,($7F80000).L
  306. .MapROMfail    MOVE.B        #$80,($DE0000).L    ; Gray BootFlag = Warmstart
  307.         RTE
  308.  
  309. .MapROMok    move.L        #$7F80000,A1        ; KickImage kopieren
  310.         MOVE.L        #$20000,D0
  311.         BRA.B        .llentry
  312.  
  313. .llouter    SWAP        D0
  314. .llinner    MOVE.L        (A0)+,(A1)+
  315. .llentry    DBRA        D0,.llinner
  316.         SWAP        D0
  317.         DBRA        D0,.llouter
  318.  
  319.         MOVE.B        #$80,($DE0000).L        ; Gray BootFlag = ColdBoot
  320.         MOVE.B        #$80,($DE0001).L
  321.  
  322.         MOVE.W        #INTF_INTEN,(_custom+intena).L    ; Alle Interrupts aus
  323.         MOVE.W        #INTFLAGS,(_custom+intreq).L    ; IRQ Requests löschen
  324.  
  325.                 MOVE.L        #-1,(4).W        ; ExecBase löschen
  326.  
  327.         LEA        ($F80002).L,A0        ; Reset Vector holen
  328.         cnop        0,4
  329.         RESET
  330.         JMP        (A0)
  331.  
  332. ****************************************************************************************************************
  333. ****************************************************************************************************************
  334. ****************************************************************************************************************
  335. ****************************************************************************************************************
  336. *
  337. *    %x000 01yy 1100 ---- ---- ---- ---- ----    Shadow Register Format
  338. *                                                       x = Set/Clr Flag
  339. *                            y = Bank Number
  340.  
  341.  
  342. MEMSHWREG    equ    $82c00000          * Shadow Enable    Control Register
  343. MYFC        equ    3        * Entry FC for Control Registers
  344.  
  345.         SECTION        CyberMap_Blizzard,CODE
  346.  
  347. _Kick2060    MOVEM.L        d0-d7/a0-A6,-(SP)
  348.                 move.l        (4).w,a6
  349.         move.l          MemList(a6),d0        ; get start of memory list
  350. .nextnode:    NEXTNODE        d0,a2,.nofast        ; Nächste Memnode holen, oder Ende
  351.         move.l          MH_LOWER(a2),d1
  352.         and.l        #$ffff0000,d1
  353.                 cmp.l        #$08000000,d1        ; Richtige Node ????
  354.                 bne.s        .nextnode
  355.                 move.l        MH_UPPER(a2),a2        ; Addresse des ShadowBereiches.
  356.                 move.l        a2,d0
  357.         subq.l        #1,d0
  358.         and.l        #$00f0000,d0        ; so jetzt noch testen, ob das Ram auf eine 0.5 MB Grenze endet
  359.         cmp.l        #$0070000,d0
  360.         bne.l        .nofast            ; wohl nicht, also ende.
  361.  
  362.         LEA        (_KickSuperCode2060,PC),A5    ; der Rest im Supervisior Mode...
  363.         JSR        (_LVOSupervisor,A6)
  364. .nofast
  365.         MOVEM.L        (SP)+,d0-d7/a0-A6
  366.         RTS
  367.  
  368. ********* a0 = Start of KickImage
  369. ********* a2 = Start of ShadowRam
  370.  
  371. _KickSuperCode2060:
  372.         ORI.W        #$700,SR        ; Lock all IRQs !
  373.         movec        DFC,D7            ; save old dfc
  374.         moveq        #MYFC,D1
  375.         movec        D1,DFC            ; set new dfc
  376.  
  377.                 moveq        #3,d0
  378.         moveq        #0,d1              ; Der Reihe nach das Shadow deaktivieren
  379.                             ; Nur eine Bank kann aktiv sein !!!!!
  380. .shadowfind:
  381.         bsr.s        _setmemshadow           ; Shadow für Bank <D0> aus
  382.                 bsr.s        _testmem        ; a2=Shadowstart -> ist da jetzt RAM
  383.                 beq.s        .MapperOk
  384.                 dbra        d0,.shadowfind
  385. .nobank                                                ; Alle Bänke durchgespielt, kein RAM aufgetaucht.....
  386.         movec        D7,DFC            ;get back old dfc
  387.         rte
  388.  
  389.  
  390. .MapperOk    move.L        A2,A1            ; KickImage kopieren (a0)->(a1)
  391.         MOVE.L        #$20000,D4
  392.         BRA.B        .llentry
  393. .llouter    SWAP        D4
  394. .llinner    MOVE.L        (A0)+,(A1)+
  395. .llentry    DBRA        D4,.llinner
  396.         SWAP        D4
  397.         DBRA        D4,.llouter
  398.  
  399.         moveq        #1,d1
  400.         bsr.s        _setmemshadow        ; Shadow wieder an.
  401.  
  402.         movec        D7,DFC            ; get back old dfc
  403.  
  404.         MOVE.W        #INTF_INTEN,(_custom+intena).L    ; Alle Interrupts aus
  405.         MOVE.W        #INTFLAGS,(_custom+intreq).L    ; IRQ Requests löschen
  406.  
  407.                 MOVE.L        #-1,(4).W        ; ExecBase löschen
  408.  
  409.         LEA        ($F80002).L,A0        ; Reset Vector holen
  410.                 cnop        0,4
  411.         RESET
  412.         JMP        (A0)
  413.  
  414.  
  415.  
  416. *********************************************************
  417. *    writes memshadowregister of the given rambank
  418. *    setmemshadow(D0=bank,D1=on/off (bool))
  419. *********************************************************
  420. *       $ 8    2    c
  421. *    %100x yy10 1100 ---- ---- ---- ---- ----    Shadow Register Format
  422. *                                                       x = Set/Clr Flag  0=on 1=off
  423. *                            y = Bank Number
  424.  
  425. _setmemshadow:
  426.         movem.l        d0-d1/a6,-(sp)
  427.         and.l        #3,D0
  428.         ror.l        #6,D0            ;shift in place
  429.         ori.l        #MEMSHWREG,d0        ;mask in MEMSHWREG adr
  430.         tst.l        D1            ;
  431.         bne        shwnotset         ; =! 0 -> TRUE -> b28=0
  432.         bset        #28,d0                  ; == 0 -> FALSE -> b28=1
  433. shwnotset:
  434.         move.l        D0,A6            ; Write Register
  435.         moves.l        A6,(A6)
  436.         movem.l        (sp)+,d0-d1/a6
  437.         rts
  438.  
  439. *********************************************************
  440. *     testmem
  441. *    a2= shadow adr start
  442. *********************************************************
  443.  
  444. _testmem:
  445.         move.l        (a2),d4            ; speicher retten
  446.         move.l        4(a2),d5
  447.         move.l        #$DEADBEEF,(a2)         ; write test long
  448.         nop
  449.         move.l          #$CAFECAFE,4(a2)    ; trash bus
  450.         nop
  451.         move.l        (a2),d6                 ; read testval long
  452.         nop
  453.         move.l        d4,(a2)         ; restore memory
  454.         move.l        d5,4(a2)
  455.         nop
  456.         cmp.l        #$DEADBEEF,d6
  457.         rts
  458.  
  459.         END
  460.  
  461.  
  462.